<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML>
<html>
  <head>
    <title>论坛版块列表</title>
   <%@include file="/WEB-INF/jsp/public/commons.jspf"%>
  </head>
<ol class="breadcrumb">
  <li><a href="home_innerCentre.action">首页</a></li>
  <li class="active">论坛版块</li>
</ol>
 <div class="container">
 
 	<div class="heading">
 		<s:if test="#session.user.hasPrivilegeByName('版块添加')">
        <button id="btnAdd" type="button" class="btn  btn-success" data-toggle="modal" data-target="#addModal">  
            <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>添加   
        </button>
        </s:if>
        <s:if test="#session.user.hasPrivilegeByName('版块修改')">
        <button id="btnEdit" type="button" class="btn  btn-warning">  
            <span class="glyphicon glyphicon-edit" aria-hidden="true"></span>修改   
        </button>
        </s:if>
        <s:if test="#session.user.hasPrivilegeByName('版块删除')">
        <button id="btnDel" type="button" class="btn  btn-danger" data-toggle="modal" data-target="#DeleteForm">  
            <span class="glyphicon glyphicon-minus" aria-hidden="true"></span>删除  
        </button>
        </s:if>
    </div> 
    <div class="widget-content padded clearfix"> 
		<table class="table table-striped table-bordered table-hover">	   
		    
		   <thead>
		      <tr class="success">
		      	<th class="check-header hidden-xs">  
                    <input id="checkAll" name="checkAll" type="checkbox">
                </th>
				<th>模块名称</th>
				<th>描述</th>
				<th>主题数</th>
				<th>总贴数</th>
				<th>移动</th>
		      </tr>
		   </thead>
		   <tbody>
		   	 <s:iterator value="recordList">
				<tr>
				    <td>  
                        <input name="checkbox" type="checkbox" id="${id }" value="${id }">  
                    </td>
                    
						<td>${name}</td>
						<td>${description}</td>
						<td>${topicCount}</td>
						<td>${articleCount}</td>
					    <td>
					        <s:a action="forum_moveUp.action?pageNum=%{currentPage}&id=%{id }">上移</s:a> |
					        <s:a action="forum_moveDown.action?pageNum=%{currentPage}&id=%{id }">下移</s:a>
					    </td>
				</tr>
			</s:iterator>
		   </tbody>
		</table>
<%--分页信息 --%>
<%@include file="/WEB-INF/jsp/public/pageView.jspf"%>
<form id="pageCondition" action="forum_list.action"></form>
</div>  
</div>
   
   <div class="modal fade in" id="addModal" tabindex="-1" role="dialog" style="display: none;" aria-labelledby="confirmModalLabel" aria-hidden="true">
		<div class="modal-dialog" >
			<div class="modal-content">
				<form  id="forumForm"  action="" method="post" enctype="multipart/form-data" role="form" style="width: 90%;margin: 0 0 0 20px">
			         <div class="modal-header">
			            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
			            <h4 class="modal-title" id="confirmModalLabel">添加模块</h4>
			         </div>
		            <input type="hidden" id="forumid" name="id"/>
		         	<div class="modal-body" id="modal_confirm">
	         			<div class="form-group">
		         	        <label for="name">模块名称</label>
						    <input type="text" id="forumname" name="name" class="form-control" placeholder="文本输入">
	         			</div>
	         			<div class="form-group" id="pic">
		         	        <label for="name">图片</label>
						    <input id="filepicture" name="file" type="file"  data-overwrite-initial="false" data-min-file-count="1" data-max-file-count="1" >
	         				<p class="help-block">支持jpg、png、gif格式，大小不超过2.0M</p>
	         			</div>
						<div class="form-group">
						    <label for="name">描述</label>
						    <textarea id="description" name="description" class="form-control" rows="3"></textarea>
						</div>
						
	
		         	 </div>
		         	
			         	<div class="modal-footer">
				            <input type="submit" id="formsubmit" class="btn btn-primary" value="确定"/>
				            <button type="button" class="btn btn-default"  data-dismiss="modal" id="cencle_button">关闭 </button>
				        </div>
	         	</form>
	         </div>
		
		</div>
	</div>
   
   
			 <!-- 信息删除确认 -->  
			<div class="modal fade" id="delcfmModel">  
			  <div class="modal-dialog modal-sm">  
			    <div class="modal-content message_align">  
			      <div class="modal-header">  
			        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>  
			        <h4 class="modal-title">提示信息</h4>  
			      </div>  
			      <div class="modal-body">  
			        <p style="text-align:center;">您确认要删除吗？</p>  
			      </div>  
			      <div class="modal-footer">
			      	 <input type="hidden" id="url"/>  
			         <button type="submit" class="btn btn-default" data-dismiss="modal">取消</button>  
			         <a id="btnConfirm" type="button" class="btn btn-primary">确定</a>  
			      </div>  
			    </div><!-- /.modal-content -->  
			  </div><!-- /.modal-dialog -->  
			</div><!-- /.modal -->  
  </body>


  <script type="text/javascript">
  		$(function(){
  			$('#addModal').modal({
	  			show:false,
	  			backdrop:false,
	  			keyboard:false
	  		}); 
  			
  			$('#forumForm').bootstrapValidator({
				message: 'This value is not valid',
				feedbackIcons: {
					valid: 'glyphicon glyphicon-ok',
					invalid: 'glyphicon glyphicon-remove',
					validating: 'glyphicon glyphicon-refresh'
					},
	            fields: {
	            	name: {
	                    message: '用户名验证失败',
	                    validators: {
	                        notEmpty: {
	                            message: '模块名称不能为空'
	                        }
	                    }
	                },
	                file: {
	                    validators: {
	                        notEmpty: {
	                            message: '图片不能为空'
	                        }
	                    }
	                },
	                description: {
	                    validators: {
	                        notEmpty: {
	                            message: '描述不能为空'
	                        }
	                    }
	                }
	            }
	        }); 
		
		/* function validatorForm(){
			alert("hhh");
			$('#forumForm').data('bootstrapValidator').validate();
			var flage=$('#forumForm').data('bootstrapValidator').isValid();
			alert("sss");
			if(!flage){
			    return false;
			}else{
				return true;
			}
		} */
  			
  			/* toastr.options = {
  					positionClass: "toast-top-right",
  					"showDuration" : "300",//显示的动画时间
  					"timeOut" : "1000"//展现时间
  					}; */
  			   
  				//添加
			 $('#btnAdd').click(function(){
				$("#confirmModalLabel").text("添加模块");
				$("#file").attr("type","file");
				$("#forumid").val(null);
	    		$("#pic").show();
				$('#forumForm').prop("action","${pageContext.request.contextPath }/forum_add.action?pageNum=${currentPage}");
	  		 });
  			//修改
  			$('#btnEdit').click(function(){
  				var id="";
  		    	$("input[name='checkbox']").each(function () { 
  		    		if($(this).prop("checked")==true){
  		    			id=$(this).prop("value");
  		    		}
                });
  		    	if(id!=""){
  		    		$.ajax({
  		    		   type: "POST",
  		    		   dataType:"json",
  		    		   url: "${pageContext.request.contextPath }/forum_findById.action",
  		    		   data: "id="+id,
  		    		   success: function(data){
  		    			 //var d=JSON.stringify(data);
  		    		     $("#confirmModalLabel").text("修改模块");
  		    		     $("#forumname").val(data.name);
  		    		   	 $("#file").attr("type","hhhh");
  		    		     $("#pic").hide();
  		    		     $("#description").val(data.description);
  		    		     $("#forumid").val(data.id);
  		    		     $("#addModal").modal();
  		    		     $("#forumForm").prop("action","${pageContext.request.contextPath }/forum_upd.action?pageNum=${currentPage}");
  		    		   }
  		    		});
  		    	}else{
  		    		$.bootstrapGrowl("请选择有效数据.",{
  						type:'warning',
  						//offset:{from: 'top', amount: 100},
  						align:'center',
  						width:250,
  						delay:4000,
  						allow_dismiss:true
  					
  					});
  		    	}
  				
  			});
  		    //全选  
            $("#checkAll").click(function () {  
            	//alert($("#checkAll").attr("checked"));
                if (this.checked) {  
                    $("input[name='checkbox']").each(function () {  
                        $(this).prop("checked", true);
                    });  
                    
                } else {  
                    $("input[name='checkbox']").each(function () {  
                        $(this).prop("checked", false);
                    });  
                    
                }  
            });  
  		    
  		    $("#btnDel").click(function(){
  		    	var ids="";
  		    	$("input[name='checkbox']").each(function () { 
  		    		if($(this).prop("checked")==true){
  		    			ids=ids+$(this).prop("value")+",";
  		    		}
                });
  		    	if(ids!=""){
  		    		ids=ids.substring(0,ids.length-1);
  		    		$('#url').val("forum_del.action?pageNum=${currentPage}&ids="+ids);
  		    		$("#delcfmModel").modal();
  		    	}else{
  		    		$.bootstrapGrowl("请选择有效数据.",{
  						type:'warning',
  						//offset:{from: 'top', amount: 100},
  						align:'center',
  						width:250,
  						delay:4000,
  						allow_dismiss:true
  					
  					});
  		    		//toastr.warning('请选择有效数据');
  		    	}
  		    	
  		    });
  		    
  		    $("#btnConfirm").click(function(){
  		    	var url=$.trim($("#url").val());//获取会话中的隐藏属性URL 
                var bb=$.bootstrapGrowl("删除成功!", {
                    type: 'success',
                    align: 'center',
                    width: 'auto',
                    allow_dismiss: true
                });
  		        window.location.href=url;
  		        //toastr.success('操作成功');
  		    });
  		});
  		
  		
		$('#filepicture').fileinput({
	        'allowedFileExtensions': ['jpg', 'png', 'gif'],
	        overwriteInitial: false,
	        showUpload: false, //是否显示上传按钮
	        showCaption: true,//是否显示标题
	        maxFileSize: 20480,
	        minImageWidth: 50, //图片的最小宽度
	        minImageHeight: 50,//图片的最小高度
	        maxImageWidth: 100,//图片的最大宽度
	        maxImageHeight: 100,//图片的最大高度
	        browseClass: "btn btn-primary", //按钮样式             
	        previewFileIcon: "<i class='glyphicon glyphicon-king'></i>",
	   });
		/* //选ze
	   function mytoggle(myid){
			alert(myid);
		   $("#"+myid).prop("checked", true);
	   } */
  </script>
  
  
</html>
